import { createRouter, createWebHistory } from "vue-router";
import routes from "./router";
import store from "@/store/index";


const router = createRouter({
  history: createWebHistory(),
  routes,
});

router.beforeEach((to, from, next) => {
  if (to.path === from.path) {
    return;
  }
  if (to.meta.requireAuth && !store.state.is_login) {
    next({ name: "user-login" });
  } else {
    next();
  }
});

export default router;
